//-----------------------------------------------------------------------------
// Name: Display.cpp
// Auth: Bradford J. Smith & Robert Darty
// Desc: methods and data for display
//-----------------------------------------------------------------------------

#include <windows.h>
#include "Display.h"

#include "Assert.h"
#include "DisplayManager.h"
#include "SharedConstants.h"
#include "Systems.h"
#include "RobTown.h"

#include "corona/corona.h"

//-----------------------------------------------------------------------------
// Globals:
//-----------------------------------------------------------------------------
DWORD gLastTickCount = 0;

//-----------------------------------------------------------------------------
// Constants:
//-----------------------------------------------------------------------------
//static const DWORD kUpdateTimeMS = 200;

//-----------------------------------------------------------------------------
// Function Definitions:
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
void ReshapeFunction(GLsizei w, GLsizei h)
{
	// update the data in the display manager
	cDisplayManager* pDisplayManager = GetDisplayManager();
	pDisplayManager->SetWindowArea(w, h);

	// update the viewport within the window
	glViewport(0, 0, w, h);

	pDisplayManager->UpdateProjection();
}

//-----------------------------------------------------------------------------
void DisplayFunction()
{
	cDisplayManager* pDisplayManager = GetDisplayManager();
	Assert(pDisplayManager != NULL);

	// clear the buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//Draws the HUD - should always be drawn first!
	pDisplayManager->DrawHUD();

	//calculates the time elapsed since last frame
	int elapsedTimeMS = (int)(GetTickCount() - gLastTickCount);
	float elapsedTimeS = (float)elapsedTimeMS / 1000.0f;
	gLastTickCount = GetTickCount();
	
	// Updates the camera - including all movement by player
	pDisplayManager->UpdateCamera(elapsedTimeS);	



	// draw the town
	cRobTown* pRobTown = GetRobTown();
	if (pRobTown)
	{
		pRobTown->Draw();
	}




	// flip the buffer to the screen
	glFlush();
	glutSwapBuffers();
}
